package thread_ex;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Scanner;

class CopyThread extends Thread{
	public void run(){
		try{
			FileInputStream fis = new FileInputStream("c:\\a1.zip");
			FileOutputStream fos = new FileOutputStream("c:\\copy.zip");
			int n =0;
			byte b[] = new byte[100];
			while((n = fis.read(b)) != -1){
				fos.write(b,0,n);
			}
			fos.close();
			fis.close();
			System.out.println("파일 복사 성공!");

		}catch(Exception e){
			System.out.println(e.getMessage());
		}
	}
}

public class Test03_FileCopy {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		while(true){
			System.out.println("1.파일복사 2.디렉토리크기 3.종료");
			int n = scan.nextInt();
			if(n == 1){
				CopyThread ct = new CopyThread();
				ct.start();
				//ct.run();
				
			}else if(n==2){
				fileSize();
			}else{
				break;
			}
		}

	}



	public static void fileSize(){
		File f = new File("c:\\workspace");
		long len = getLen(f);
		System.out.println("디렉토리 크기 : " + len + " bytes");	
	}

	public static long getLen(File f){
		File list[] = f.listFiles();
		long len = 0;
		for (int i = 0; i<list.length;i++){
			if(list[i].isFile()){
				len += list[i].length();
			}else{
				len += getLen(list[i]);
			}
		}
		return len;
	}
}
